const tokens = {
    admin: {
        token: 'admin-token'
    },
    editor: {
        token: 'editor-token'
    },
    // user: {
    //     token: 'user-token'
    // }
}
const userList = [{
        loginName: 'admin',
        createdate: "2020-12-31",
        name: '管理员',
        password: '12345',
        token: 'admin-token',
        roles: ['admin'],
        address: '上海市普陀区金沙江路 1518 弄'
    }, {
        loginName: 'admin1',
        createdate: "2020-12-31",
        password: '12345',
        roles: ['admin'],
        address: '上海市普陀区金沙江路 1518 弄',
        name: '张si',
        age: 24,
        sex: '男',
        avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
        birthday: '2022-04-01',
        phone: '',
        email: ''
    },
    {
        loginName: 'editor',
        name: '操作员',
        createdate: "2020-12-31",
        password: '12345',
        token: 'editor-token',

        roles: ['editor'],
        address: '上海市普陀区金沙江路 1518 弄'
    }, {
        loginName: 'useradmin',
        name: '王小虎',
        createdate: "2020-12-31",
        password: '12345',
        roles: ['editor'],
        address: '上海市普陀区金沙江路 1518 弄'
    }, {
        loginName: 'user',
        createdate: "2020-12-31",
        name: '王小虎',
        password: '12345',
        roles: ['editor'],
        address: '上海市普陀区金沙江路 1518 弄'
    }
]
const users = {
    'admin-token': {
        roles: ['admin'],
        introduction: 'I am a super administrator',
        avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
        name: '超级管理员'
    },
    'editor-token': {
        roles: ['editor'],
        introduction: 'I am an editor',
        avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
        name: '操作员'
    },
    // 'user-admin-token': {
    //     roles: ['editor'],
    //     introduction: 'I am an user-admin',
    //     avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    //     name: '管理员'
    // },
    // 'user-token': {
    //     roles: ['editor'],
    //     introduction: 'I am an user',
    //     avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    //     name: '新用户'
    // }
}
const operatorList = [{
    id: 1,
    label: '管理部门',
    children: [{
        id: 4,
        label: '徐八',
    }]

}, {
    id: 2,
    label: '研发部门',
    children: [{
        id: 5,
        label: '王五'
    }, {
        id: 6,
        label: '赵六'
    }]
}, {
    id: 3,
    label: '维修部门',
    children: [{
        id: 7,
        label: '张三'
    }, {
        id: 8,
        label: '李四'
    }]
}]
module.exports = [
    // user login
    {
        url: '/vue-admin-template/user/login',
        type: 'post',
        response: config => {
            const { loginName } = config.body
            for (let i = 0; i < userList.length; i++) {
                if (userList[i].loginName == loginName) {
                    return {
                        code: 20000,
                        data: userList[i]
                    }
                }
            }
            return {
                code: 60204,
                data: '账号密码不正确'
            }
        }
    },
    // get operator 
    {
        url: '/vue-admin-template/user/getOperator',
        type: 'get',
        response: config => {
            // mock error
            // if (!info) {
            //     return {
            //         code: 50008,
            //         message: 'Login failed, unable to get user details.'
            //     }
            // }

            return {
                code: 20000,
                data: operatorList
            }
        }
    },
    // get user info
    {
        url: '/vue-admin-template/user/info\.*',
        type: 'get',
        response: config => {

            const { token } = config.query
            const info = users[token]

            // mock error
            if (!info) {
                return {
                    code: 50008,
                    message: 'Login failed, unable to get user details.'
                }
            }

            return {
                code: 20000,
                data: info
            }
        }
    },
    // get userList
    {
        url: '/vue-admin-template/user/list',
        type: 'post',
        response: config => {

            return {
                code: 20000,
                data: userList
            }
        }
    },
    // get userMessage
    {
        url: '/vue-admin-template/user/message',
        type: 'post',
        response: config => {
            let loginName = config.body.loginName
            for (let i = 0; i < userList.length; i++) {
                if (userList[i].loginName == loginName) {
                    return {
                        code: 20000,
                        data: userList[i]
                    }
                }


            }
        }

    },
    // update userMessage
    {
        url: '/vue-admin-template/user/updateMessage',
        type: 'post',
        response: config => {
            let loginName = config.body.loginName
            for (let i = 0; i < userList.length; i++) {
                if (userList[i].loginName == loginName) {
                    userList[i] = config.body
                    return {
                        code: 20000,
                        data: '修改成功'
                    }
                }


            }
        }

    },
    // user logout
    {
        url: '/vue-admin-template/user/logout',
        type: 'post',
        response: _ => {
            return {
                code: 20000,
                data: 'success'
            }
        }
    },
    // user register
    {
        url: '/vue-admin-template/user/register',
        type: 'post',
        response: config => {
            // 默认注册操作员
            let obj = {
                loginName: config.body.username,
                createdate: "2020-12-31",
                password: config.body.password,
                roles: ['admin'],
                address: '上海市普陀区金沙江路 1518 弄',
                name: '张si',
                token: 'admin-token',
                age: 24,
                sex: '男',
                avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
                birthday: '2022-04-01',
                phone: '',
                email: ''
            }
            userList.push(obj)


            return {
                code: 20000,
                data: obj
            }
        }
    },
    // user updateMessage
    {
        url: '/vue-admin-template/user/updateMessage',
        type: 'post',
        response: config => {
            newUserMessage = config.body

            return {
                code: 20000,
                data: '修改成功'
            }
        }
    },
    // user updatePassword
    {
        url: '/vue-admin-template/user/updatePassword',
        type: 'post',
        response: config => {
            updateData = config.body
            return {
                code: 20000,
                data: '修改成功,请重新登陆'
            }
        }
    }
]